<?php
	
	$_userid = $_userid == 1 && $userid  ? $userid : $_userid; // 管理员编辑其他会员信息权限
	
	//if(!isset($action)) $action = 'manage';
	require_once 'includes/yellowpage.class.php';
	require_once 'includes/apply.class.php';
	$yellowpage = new yellowpage();
	$yellowpage->set_model('job');
	
	$a = new apply();
	$a->set_userid($_userid);
	
	switch($action){
		case 'manage':		
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			
			$page = intval($page);
			if(!$page)$page = 1;
			$applys = $a->get_job_stock_list($_userid,$page);
			$pages = pages($applys['number'],$page,15);
			include template('apply_manage.html','yellowpage');
		break;
		
		/*人才搜索*/
		case 'search':
			if($dosubmit){
				$head['keywords'] .= '人才搜索结果';
				$head['description'] .= '人才搜索结果'.'_'.$SETTING['sitename'];
				$head['title'] .= '人才搜索结果'.'_'.$SETTING['sitename'];
				if($page<1)$page = 1;
				
				require_once 'includes/apply.class.php';
				$apply = new apply();
				$rs = $apply->search_apply_result($q,$inputtime,$degree,$station,$workplace,$experience,$page);
				$pages = pages($rs['number'],$page,15);
				
				include template('apply_searchlist.html','yellowpage');
			}
			else{
				$head['keywords'] .= '人才搜索';
				$head['description'] .= '人才搜索'.'_'.$SETTING['sitename'];
				$head['title'] .= '人才搜索'.'_'.$SETTING['sitename'];
				include template('apply_search.html','yellowpage');
			}
		break;
		
		case 'showapply':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
		
			$stockid = intval($stockid);
			if(!$stockid)exit("error");
			else
			{
				$r = $a->get_stock_by_id($stockid);		
				if($r)
				{
					if(!$r['status'])$a->show_apply($stockid);
					header("location:../apply.php?applyid={$r['applyid']}");
					exit();
				}
				else exit('error');
			}
			include template('apply_manage.html','yellowpage');
		break;
		
		case 'invite':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
		 
			$stockid = intval($stockid);
			if(!$stockid)exit('0');
			else
			{
				$r = $a->get_stock_by_id($stockid);		
				if($r)
				{
					if($r['status'] != 2)
					{
						$a->show_apply($stockid,2);
						$t = $a->get_userid_by_applyid($r['applyid']);
						$j = $a->get_userid_by_jobid($r['jobid']);
						$subject = "面试通知";
						$content = "{$r['username']}你好，感谢你应聘 {$j['companyname']} 的 {$j['title']} 职位，现邀请您前来参加面试。请您做好面试准备，我们将在近期电话联系您！";			
						require_once(WWW_ROOT."message/message.class.php");
						$message = new message();
						$message->send_new($t['userid'], $j['userid'], $subject,$content);	
						if($t['email'])
						{
							require_once(WWW_ROOT."includes/sendmail.class.php");
							$sendmail = new sendmail();
							$sendmail->smtp($t['email'], $subject, $content);			
						}
					}
					echo '1';
					exit();
				}else exit('0');
			}
			include template('apply_manage.html','yellowpage');
		break;
		
		
		
		case 'show':
			require_once 'includes/apply.class.php';
			$a = new apply();
			$a->set_userid($_userid);
			$avatar = avatar($_userid);
			$r = $a->get($applyid, 1);
			if($r)
			{
				extract($r);
			}
			else
			{
				header("Location: myjob.php?action=add");
				exit;
			}
			if($status != 3)
			{
				if(!$company_user_infos)
				{
			
					$MS['title'] = '当前简历已经被锁定，不能查看！';
					$MS['description'] = '你可以做下面操作';
					$MS['urls'][0] = array(
						'name'=>'返回进入前的页面',
						'url'=>'javascript:history.back(-1)',
						);
					msg($MS);
				}
			}
			$montharr = array('01','02','03','04','05','06','07','08','09','10','11','12');
			$dayarr = array('01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31');
			$station = $TYPE[$station][name];
			if($_userid)
			{
				/*if(in_array($_groupid,$M['priv_roleid']))
				{
					$allowview = 1;
				}
				else
				{*/
					$r = $a->get_stock_by_useridandapplyid($_userid,$applyid);
					if($r)$allowview = 1;
					else $allowview = NULL;
				//}
			}
			include template('apply_show.html','yellowpage');
		break;
		
		default:
			$head['keywords'] .= '简历列表';
			$head['description'] .= '简历列表'.'_'.$PHPCMS['sitename'];
			$head['title'] .= '简历列表'.'_'.$PHPCMS['sitename']; 
			
			if($inputtime)
			$time = time() - 3600*$inputtime*24;
			else $time = 0;
			if($time < 0 )$time = 0;
			$where = "edittime >= '{$time}' ";
			$genre = urldecode($genre);
			if($experience)$where .= "AND experience >= '{$experience}' ";
			if($genre)$where .= "AND edulevel = '{$genre}' ";
			
			include template('apply.html',$module);
		break;
	}
?>